<!DOCTYPE html>
<!--suppress ALL -->
<html >
<head>
    <meta charset="UTF-8"/>
    <title>登录</title>


    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0"/>


    <script src="/js/common.js"></script>
    <script src="https://cdn.jsdelivr.net/vue.resource/1.2.1/vue-resource.min.js"></script>
</head>
<style>
    .container{
        background-color: transparent;
    }
    .navbar{
        background: #d2edf4;
        background-image: linear-gradient(to bottom, #f5807d, #e1e5f0 100%);
    }
</style>
<body>
<nav class="navbar navbar-default">
    <div class="container-fluid">
        <div class="navbar-header">
            <a class="navbar-brand" href="#"></a>
        </div>

        <div class="collapse navbar-collapse">
        </div>
    </div>
</nav>
<div class="container" id="app">
<form action="user/login" name="loginForm" id="loginForm" onsubmit="return false">
          <div class="post" id="login">
              <div class="form-group">
                  <label >用户名：</label>
                  <input  class="form-control" name="userName" id="userName" type="text" v-model="userName" required placeholder="用户名"/>
              </div>
              <div class="form-group">
                  <label >密码：</label>
                  <input class="form-control" name="passWord" id="passWord" v-model="password" type="password" required placeholder="密码"/>
              </div>
              <div class="form-group">
                  用户类型：
                  <input  name="type" id="admin" type="radio" value="1" v-model="type"/>管理员
                  <input  name="type" id="user" type="radio" value="2" v-model="type"/>普通用户<br><br>
                  <a href="javascript:location.href='/toRegister'">普通用户注册</a>
              </div>
              <div class="form-group"> <button  class="btn btn-primary  btn-block" v-on:click="login()">登录</button></div>
          </div>

      </form>
</div>
<script>

    var app = new Vue({
        el: '#app',
        data: {
            type: '',
            userName: '',
            password: '',
            items: [
            ]
        },
        methods: {
            login: function () {
                var userName=app.userName;
                var password=app.password;
                var type=app.type;
                if (type==1){
                    if (userName!="admin"||password!="admin"){
                        alert("账号或者密码错误");
                    }
                    else {
                        location.href="adminMain";
                    }
                }
                if (type==2){
                    var data = {
                        userName: userName,
                        password:password
                    };
                    $.ajax({
                        cache: true,
                        type: "POST",
                        url: "/user/dologin",
                        data: data,
                        error: function (request) {
                            alert("连接错误")
                        },
                        success: function (data) {
                            if (data.code == 200) {
                                location.href = "main";
                            }
                            if (data.code == 404) {
                                alert("用户名或密码错误");
                            }

                        }
                    })
                }
            },
        }
    });



</script>
</body>
</html>